import { defineStore } from 'pinia'

interface UserState {
  name: string
  token: string
}

export const useUserStore = defineStore<'user', UserState, {}, {
  setUser(name: string, token: string): void
  logout(): void
}>(
  'user',
  {
    state: (): UserState => ({
      name: '',
      token: ''
    }),
    actions: {
      setUser(name: string, token: string) {
        this.name = name
        this.token = token
      },
      logout() {
        this.name = ''
        this.token = ''
      }
    },
    persist: true
  }
) 